package com.ja.openchat.ui.chat.redpacket;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.chad.library.adapter.base.module.BaseLoadMoreModule;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.ja.openchat.R;
import com.zy.openchat.core.model.redpacket.RedPacketInfo;
import com.zy.openchat.util.TimeConvertUtils;

import org.jetbrains.annotations.NotNull;

public class RedPacketRecordAdapter extends BaseQuickAdapter<RedPacketInfo, BaseViewHolder> implements LoadMoreModule {

    private boolean mIsSendType = false;
    public RedPacketRecordAdapter(boolean isSendType) {
        super(R.layout.item_trade_record);
        mIsSendType = isSendType;
        setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull @NotNull BaseQuickAdapter<?, ?> adapter, @NonNull @NotNull View view, int position) {
                RedPacketDetailActivity.startActivity(getContext(),getItem(position));
            }
        });
    }

    @Override
    protected void convert(@NotNull BaseViewHolder helper, RedPacketInfo info) {
        String typeContent = "";
        switch (info.type){
            case 1:
                typeContent = "单聊红包";
                break;
            case 2:
                typeContent = "拼手气红包";
                break;
            case 3:
                typeContent = "普通红包";
                break;
            default:
                typeContent = "未知红包";
                break;
        }
        helper.setText(R.id.trade_title,typeContent);
        helper.setText(R.id.trade_date, TimeConvertUtils.formatDate9(info.createAt*1000));
        if(mIsSendType){
            helper.setText(R.id.trade_value,String.format("%.2f元",info.total_price));
            helper.setGone(R.id.trade_status,false);
            helper.setTextColor(R.id.trade_status, ContextCompat.getColor(getContext(),R.color.color_999999));
            helper.setText(R.id.trade_status,String.format("已领完 %d/%d",info.users!=null?info.users.size():0,info.count));
        }else{
            helper.setText(R.id.trade_value,String.format("%.2f元",info.curUserRpPrice()));
            helper.setGone(R.id.trade_status,true);
        }


    }

    @NonNull
    @Override
    public BaseLoadMoreModule addLoadMoreModule(@NonNull BaseQuickAdapter<?, ?> baseQuickAdapter) {
        return new BaseLoadMoreModule(baseQuickAdapter);
    }
}
